//
//  NSLockDemo.m
//  MultiperThreadTest02
//
//  Created by FelixYin on 2020/4/5.
//  Copyright © 2020 FelixYin. All rights reserved.
//

#import "NSLockDemo.h"

@interface NSLockDemo ()

@property (nonatomic,strong) NSLock *moneyLock;
@property (nonatomic,strong) NSLock *ticketLock;
@property (nonatomic,strong) NSRecursiveLock *moneyLock2;
@property (nonatomic,strong) NSRecursiveLock *ticketLock2;


@end



/*
 NSLock 是对pthread中mutexlock普通锁的封装
 
 NSRecursiveLock 是对pthread中mutexlock递归锁的封装
 
 NSCondition 是对pthread中mutexcond条件的封装
 
 */
@implementation NSLockDemo

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.moneyLock = [[NSLock alloc] init];
        self.ticketLock = [[NSLock alloc] init];
    }
    return self;
}

- (void)saveMoney{
    [self.moneyLock lock];
    [super saveMoney];
    [self.moneyLock unlock];
}

- (void)drawMoney{
    [self.moneyLock lock];
    [super drawMoney];
    [self.moneyLock unlock];
}

- (void)saleTicket{
    [self.ticketLock lock];
    [super saleTicket];
    [self.ticketLock unlock];
}

@end
